package cn.drew.org.service.impl;

import cn.drew.basic.utils.PageList;
import cn.drew.org.domain.SystemDictionaryDetail;
import cn.drew.org.mapper.SystemDictionaryDetailMapper;
import cn.drew.org.query.SystemDictionaryDetailQuery;
import cn.drew.org.service.SystemDictionaryDetailService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

@Service
public class SystemDictionaryDetailServiceImpl implements SystemDictionaryDetailService {

    @Autowired
    private SystemDictionaryDetailMapper systemDictionaryDetailMapper;
    @Override
    public void add(SystemDictionaryDetail systemDictionaryDetail) {
        systemDictionaryDetailMapper.add(systemDictionaryDetail);
    }

    @Override
    public void update(SystemDictionaryDetail systemDictionaryDetail) {
        systemDictionaryDetailMapper.update(systemDictionaryDetail);
    }

    @Override
    public void delete(Long id) {
        systemDictionaryDetailMapper.delete(id);
    }

    @Override
    public SystemDictionaryDetail findById(Long id) {
        return systemDictionaryDetailMapper.findById(id);
    }

    @Override
    public List<SystemDictionaryDetail> findAll() {
        return systemDictionaryDetailMapper.findAll();
    }



    @Override
    public PageList<SystemDictionaryDetail> queryByPage(SystemDictionaryDetailQuery systemDictionaryDetailQuery) {
        Integer count = systemDictionaryDetailMapper.queryByCount(systemDictionaryDetailQuery);
        if (count == 0 || count == null){
            return new PageList(0,new ArrayList());
        }else{
            List<SystemDictionaryDetail> systemDictionaryDetails = systemDictionaryDetailMapper.queryByPage(systemDictionaryDetailQuery);
            return new PageList<SystemDictionaryDetail>(count,systemDictionaryDetails);
        }

    }

    @Override
    public void patchDelete(List<Long> ids) {
        systemDictionaryDetailMapper.patchDelete(ids);
    }

    @Override
    public List<SystemDictionaryDetail> findBytypesid(Long typesid) {
        List<SystemDictionaryDetail> systemDictionaryDetails = systemDictionaryDetailMapper.findAll();
        System.out.println(typesid);
        //将departmentId 和deptid 相等的数据过滤 ,再转化为list
        return systemDictionaryDetails.stream().filter(systemDictionaryDetail -> typesid.equals(systemDictionaryDetail.getTypesId())).collect(Collectors.toList());

    }
}
